package org.jeecg.modules.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.system.entity.SysRole;
import org.jeecg.modules.system.entity.SysUserRole;
import org.jeecg.modules.system.mapper.SysRoleMapper;
import org.jeecg.modules.system.mapper.SysUserRoleMapper;
import org.jeecg.modules.system.service.ISysUserRoleService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;

/**
 * <p>
 * 用户角色表 服务实现类
 * </p>
 *
 * @Author scott
 * @since 2018-12-21
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {
    @Resource
    private SysUserRoleMapper sysUserRoleMapper;
    @Resource
    private SysRoleMapper sysRoleMapper;

    @Override
    public java.lang.String getRoleNameByUser(java.lang.String id) {
        QueryWrapper<SysUserRole> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",id);
        List<SysUserRole> userRoles = sysUserRoleMapper.selectList(wrapper);
        java.lang.String userType = "";
        for (SysUserRole ur:userRoles){
            SysRole sysRole = sysRoleMapper.selectById(ur.getRoleId());
            if (sysRole!=null){
                if (userType.equals("")){
                    userType=sysRole.getRoleName();
                }else {
                    userType=userType+","+sysRole.getRoleName();
                }
            }
        }
        return userType;
    }
}
